<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>client</title>
    <link href="favicon.ico" ref="short icon">
    <link rel="stylesheet" href="https://unpkg.com/element-ui/lib/theme-chalk/index.css">
</head>
<body>
<div id="app" v-cloak>
    <el-descriptions title="用户信息">
        <el-descriptions-item label="用户名">{{user.username}}</el-descriptions-item>
        <el-descriptions-item label="权限">{{user.authorities}}</el-descriptions-item>
    </el-descriptions>
    <el-button @click="logout()">退出登录</el-button>
</div>
<script src="https://unpkg.com/vue@2/dist/vue.js"></script>
<script src="https://unpkg.com/element-ui/lib/index.js"></script>
<script src="https://cdn.staticfile.org/vue-resource/1.5.1/vue-resource.min.js"></script>
<script>
    new Vue({
        el: '#app',
        data() {
            return {
                user: {}
            }
        },
        created() {
            this.$http.post('http://127.0.0.1:8080/uaa/user/get/info').then(res => {
                console.info("res",JSON.stringify(res))
                if (res.status == '200') {
                    this.user = res.body
                } else {
                    this.$message({
                        type: 'error',
                        message: res.statusText
                    });
                }
            }).catch(res => {
                console.error(res)
            })
        },
        methods: {
            logout() {
                this.$confirm('确认退出?', '提示', {
                    confirmButtonText: '确定',
                    cancelButtonText: '取消',
                    type: 'warning'
                }).then(() => {
                    //todo 退出处理
                    this.$http.post('http://127.0.0.1:8080/user/logout').then(res => {
                        console.info("res",JSON.stringify(res))
                        if (res.status == '200') {
                            window.location = "http://127.0.0.1:8080/login.html"
                        } else {
                            this.$message({
                                type: 'error',
                                message: res.statusText
                            });
                        }
                    }).catch(res => {
                        console.error(res)
                    })
                    this.$message({
                        type: 'warning',
                        message: '退出功能未开发'
                    });
                }).catch(() => {
                    this.$message({
                        type: 'info',
                        message: '已取消登录'
                    });
                });
            },
        }
    })
</script>
</body>
</html>